package ch.ethz.fcl.metrofont;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;
import javax.swing.*;
 
public class LoadAndShow extends Component {
    RescaleOp rop;
    float[] colors = {1f, 1f, 1f, 1f};
	private static final long serialVersionUID = 1L;
	BufferedImage image;
    Dimension size = new Dimension();
 
    public LoadAndShow(BufferedImage image) {
        this.image = image;
        size.setSize(image.getWidth(), image.getHeight());
    }
     
    /**
     * Drawing an image can allow for more
     * flexibility in processing/editing.
     */
    protected void paintComponent(Graphics g) {
        // Center image in this component.
        int x = (getWidth() - size.width)/2;
        int y = (getHeight() - size.height)/2;
        g.drawImage(image, x, y, this);
    }
 
    public Dimension getPreferredSize() { return size; }
 

	// public static void main(String[] args) throws IOException {
	// String path = "images/hawk.jpg";
	// BufferedImage image = ImageIO.read(new File(path));
	// LoadAndShow test = new LoadAndShow(image);
	// JFrame f = new JFrame();
	// f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	// f.add(new JScrollPane(test));
	// f.setSize(2000,200);
	// f.setLocation(1000,1000);
	// f.setVisible(true);
	// //showIcon(image);
	// }
 
    /**
     * Easy way to show an image: load it into a JLabel
     * and add the label to a container in your gui.
     */
    public static void showIcon(BufferedImage image) {
        ImageIcon icon = new ImageIcon(image);
        JLabel label = new JLabel(icon, JLabel.CENTER);
        JOptionPane.showMessageDialog(null, label, "icon", -1);
    }
}